<extend name="Public/base"/>
<block name="content">
  <div class="admin-content">
    <div class="admin-content-body">
      <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">{$title}</strong>  <small></small></div>
      </div>

      <hr/>

      <div class="am-g">
        <div class="am-u-sm-12 am-u-md-8 am-u-md-push-1">
          <form class="am-form am-form-horizontal" action="{:U()}" method="post">
            <input type="hidden" name="id" value="{$data['id']}">
            <input type="hidden" name="type" value="1">
            <div class="am-form-group">
              <label for="user-name" class="am-u-sm-3 am-form-label">公告名称</label>
              <div class="am-u-sm-9">
                <input type="text" id="user-name" placeholder="" required name="title" value="{$data.title}">
                <span style="color: red;font-size: 13px">标题尽量简短</span>
              </div>
            </div>
            <div class="am-form-group" id="college">

            </div>

            <!--<div class="am-form-group">-->
              <!--<label for="user-email" class="am-u-sm-3 am-form-label">公告内容</label>-->
              <!--<div class="am-u-sm-9">-->
                <!--<textarea class="" rows="5" id="doc-ta-1"  name="content" required>{$data.content}</textarea>-->
              <!--</div>-->
            <!--</div>-->

            <div class="am-form-group">

              <label for="doc-ta-1" class="am-u-sm-3 am-form-label">公告内容</label>
              <div class="am-u-sm-9">
              <textarea style="min-width: 628px" id="container" name="content" type="text/plain">
                                    {$data.content}
                            </textarea>
              </div>

              <!--<textarea class="" rows="5" id="doc-ta-1"></textarea>-->
            </div>
            <!--<div class="am-form-group">-->
              <!--<label for="user-QQ" class="am-u-sm-3 am-form-label">公告类别</label>-->
              <!--<div class="am-u-sm-9">-->
                <!--<select data-am-selected="{btnSize: 'sm'}" name="type">-->
                  <!--<option value="1" <php>if($data['type'] == 1) echo 'selected'</php>>商城新闻</option>-->
                    <!--<option value="2" <php>if($data['type'] == 2) echo 'selected'</php>>医院简介</option>-->
                <!--</select>-->
              <!--</div>-->
            <!--</div>-->

            <div class="am-form-group">
              <label for="user-QQ" class="am-u-sm-3 am-form-label">是否启用</label>
             <div class="am-u-sm-9">
               <label class="am-radio-inline">
                 <input type="radio" name="status" value="1" <php>if($data['status'] == 1 || !isset($data['status'])) echo 'checked'</php> data-am-ucheck> 是
               </label>
               <label class="am-radio-inline">
                 <input type="radio" name="status" value="2" <php>if($data['status'] == 2) echo 'checked'</php> data-am-ucheck> 否
               </label>
             </div>
            </div>
            <div class="am-form-group">
              <label for="user-QQ" class="am-u-sm-3 am-form-label">分类</label>
              <div class="am-u-sm-9">
              <label class="am-radio-inline">
              <input type="radio" name="type" value="1" <php>if($data['type'] == 1) echo 'checked'</php> data-am-ucheck> 平台公告
              </label>
              <label class="am-radio-inline">
              <input type="radio" name="type" value="2" <php>if($data['type'] == 2) echo 'checked'</php> data-am-ucheck> 系统消息
              </label>
                <label class="am-radio-inline">
                  <input type="radio" name="type" value="3" <php>if($data['type'] == 3) echo 'checked'</php> data-am-ucheck> 关于我们
                </label>
                <label class="am-radio-inline">
                  <input type="radio" name="type" value="4" <php>if($data['type'] == 4) echo 'checked'</php> data-am-ucheck> 联系我们
                </label>
              </div>
            </div>
            <div class="am-form-group">
              <label for="user-QQ" class="am-u-sm-3 am-form-label">语言版本</label>
              <div class="am-u-sm-9">
                <label class="am-radio-inline">
                  <input type="radio" name="language" value="1" <php>if($data['language'] == 1 || !isset($data['status'])) echo 'checked'</php> data-am-ucheck> 英语
                </label>
                <label class="am-radio-inline">
                  <input type="radio" name="language" value="2" <php>if($data['language'] == 2) echo 'checked'</php> data-am-ucheck> 汉语
                </label>
                <!--<label class="am-radio-inline">-->
                  <!--<input type="radio" name="language" value="3" <php>if($data['language'] == 3) echo 'checked'</php> data-am-ucheck> 越南语-->
                <!--</label>-->
              </div>
            </div>

            <div class="am-form-group">
              <div class="am-u-sm-9 am-u-sm-push-3">
                <button type="submit" class="am-btn am-btn-primary">保存修改</button>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</block>
<block name="js">
  <script type="text/javascript" src="__LIB__/ueditor/ueditor.config.js"></script>
  <script type="text/javascript" src="__LIB__/ueditor/ueditor.all.js"></script>
  <script type="text/javascript">
      var ue = UE.getEditor('container');

  </script>
  <script>


    $(function () {
        var form = $('form');

        $("[name='type']").change(function () {
          if ($(this).val() == 5){
            $("#college").append(`<label for="user-name" class="am-u-sm-3 am-form-label">新闻logo</label>
              <div class="am-u-sm-9">
                <input type="file" id="upload_college" placeholder="" required name="upload_college" value="">
                <input type="hidden" id="img" name="img">
                <img src="" id="img_show" style="width: 8rem;height: 8rem" alt="">
              </div>`);
          } else {
            $("#college").html('')
          }
        })
      $(document).on("change","#upload_college",function () {
        var formData = new FormData();
        formData.append("file", $(this).get(0).files[0]);
        $.ajax({
          url:"{:U('Reward/logo_change')}",
          dataType:'json',
          type:'POST',
          data:formData,
          cache: false,
          contentType: false,    //不可缺
          processData: false,    //不可缺
          success:function(data){
            console.log(data.path)
            if(data.code == 1){
              // alert(data.path);
              $("#img_show").attr('src',data.path);
              $("#img").val(data.path);
              // $("#pic_up_img").attr("src",data.path);//将php传过来的图片付给图片src显示
              // $("#idcard_up").val(data.path);//将路径保存到hidden里通过form一起保存
            }else{
              alert(data.message);
            }
          }
        });
      })
        $('form').submit(function (e) {
         if ($("[name='type']").val() == 5){
           if ($("#img").val() == ''){
             alert('请上传logo');
             return false
           }
         }
            e.preventDefault();
            $.post(form.attr('action'),form.serialize(),function (data) {
                // console.log(data);return false;
                layer.msg(data.msg,{time:1000},function () {
                    if(data.code){
                        return false;
                    }else{
                        window.location.href=data.data;
                    }
                })

            },'json')
        })
    })
  </script>
</block>